package com.qiche.service.impl;

import java.util.List;

import javax.annotation.Resource;

import com.qiche.mapper.CarVehicleMapper;
import com.qiche.model.CarVehicle;
import com.qiche.service.CarVehicleService;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

import tk.mybatis.mapper.entity.Example;

/**
 * Created by Linzw on 2018/01/24.
 */
@Service("carVehicleService")
public class CarVehicleServiceImpl extends BaseService<CarVehicle> implements CarVehicleService {

	@Resource
	private CarVehicleMapper mapper;
	@Override
	public PageInfo<CarVehicle> selectByPage(CarVehicle brand, int start, int length) {
		int page = start / length + 1;
		Example example = new Example(CarVehicle.class);
		Example.Criteria criteria = example.createCriteria();
		// 分页查询
		PageHelper.startPage(page, length);
		List<CarVehicle> regionList = selectByExample(example);
		return new PageInfo<>(regionList);
	}

	@Override
	public CarVehicle selectById(Long vehicleId) {
		Example example = new Example(CarVehicle.class);
		Example.Criteria criteria = example.createCriteria();
		criteria.andEqualTo("id", vehicleId);
		List<CarVehicle> regionList = selectByExample(example);
		if (regionList.size() > 0) {
			return regionList.get(0);
		}
		return null;
	}

	@Override
	public List<CarVehicle> selectAll() {
		return mapper.selectByExample(null);
	}

}
